Add rustc/rustdoc config keys to Cargo config
authorAlex Crichton <alex@alexcrichton.com>
Mon, 18 May 2015 22:57:17 +0000 (15:57 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 19 May 2015 04:11:51 +0000 (21:11 -0700)
In addition to global RUSTC/RUSTDOC env vars, this commit recognizes
`build.rustc` and `build.rustdoc` as configuration keys for Cargo to instruct
what tools should be used instead of the default.

Closes #967

16 files changed:
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/compilation.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/engine.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs
src/cargo/util/config.rs
src/cargo/util/mod.rs
src/doc/config.md
tests/test_bad_config.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_custom_build.rs
tests/test_cargo_compile_plugins.rs
tests/test_cargo_cross_compile.rs
tests/tests.rs

index 74137e9efbc23bf3a5abe624792bad807aac09f2..26db527dcd87fc903a92470aec27e3315a175fb3 100644 (file)
@@ -82,9 +82,9 @@ pub enum CompileFilter<'a> {
     }
 }
 
-pub fn compile(manifest_path: &Path,
-               options: &CompileOptions)
-               -> CargoResult<ops::Compilation> {
+pub fn compile<'a>(manifest_path: &Path,
+                   options: &CompileOptions<'a>)
+                   -> CargoResult<ops::Compilation<'a>> {
     debug!("compile; manifest-path={}", manifest_path.display());
 
     let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
@@ -101,8 +101,9 @@ pub fn compile(manifest_path: &Path,
     compile_pkg(&package, options)
 }
 
-pub fn compile_pkg(package: &Package, options: &CompileOptions)
-                   -> CargoResult<ops::Compilation> {
+pub fn compile_pkg<'a>(package: &Package,
+                       options: &CompileOptions<'a>)
+                       -> CargoResult<ops::Compilation<'a>> {
     let CompileOptions { config, jobs, target, spec, features,
                          no_default_features, release, mode,
                          ref filter, ref exec_engine,
@@ -174,10 +175,12 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
             profile.rustc_args = Some(args.to_vec());
             Some((target, profile))
         }
-        Some(_) =>
-            return Err(human("extra arguments to `rustc` can only be passed to one target, \
-                              consider filtering\nthe package by passing e.g. `--lib` or \
-                              `--bin NAME` to specify a single target")),
+        Some(_) => {
+            return Err(human("extra arguments to `rustc` can only be passed to \
+                              one target, consider filtering\nthe package by \
+                              passing e.g. `--lib` or `--bin NAME` to specify \
+                              a single target"))
+        }
         None => None,
     };
 
@@ -195,7 +198,8 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
 
         try!(ops::compile_targets(&targets, to_build,
                                   &PackageSet::new(&packages),
-                                  &resolve_with_overrides, &sources,
+                                  &resolve_with_overrides,
+                                  &sources,
                                   config,
                                   build_config,
                                   to_build.manifest().profiles()))
index 302e6fd9e2e988e43966e2f370a6526b91d663b0..bd6be3c4c843c353d57f270ecfedbe8885b77abd 100644 (file)
@@ -4,12 +4,12 @@ use std::path::PathBuf;
 use semver::Version;
 
 use core::{PackageId, Package, Target};
-use util::{self, CargoResult};
+use util::{self, CargoResult, Config};
 
 use super::{CommandType, CommandPrototype};
 
 /// A structure returning the result of a compilation.
-pub struct Compilation {
+pub struct Compilation<'cfg> {
     /// All libraries which were built for a package.
     ///
     /// This is currently used for passing --extern flags to rustdoc tests later
@@ -44,10 +44,12 @@ pub struct Compilation {
 
     /// Features enabled during this compilation.
     pub features: HashSet<String>,
+
+    config: &'cfg Config,
 }
 
-impl Compilation {
-    pub fn new(pkg: &Package) -> Compilation {
+impl<'cfg> Compilation<'cfg> {
+    pub fn new(pkg: &Package, config: &'cfg Config) -> Compilation<'cfg> {
         Compilation {
             libraries: HashMap::new(),
             native_dirs: HashMap::new(),  // TODO: deprecated, remove
@@ -58,6 +60,7 @@ impl Compilation {
             extra_env: HashMap::new(),
             package: pkg.clone(),
             features: HashSet::new(),
+            config: config,
         }
     }
 
@@ -98,7 +101,7 @@ impl Compilation {
         search_path.push(self.deps_output.clone());
         let search_path = try!(util::join_paths(&search_path,
                                                 util::dylib_path_envvar()));
-        let mut cmd = try!(CommandPrototype::new(cmd));
+        let mut cmd = try!(CommandPrototype::new(cmd, self.config));
         cmd.env(util::dylib_path_envvar(), &search_path);
         for (k, v) in self.extra_env.iter() {
             cmd.env(k, v);
index 3abb93e09afcff5b43b2d1bda6da0aac64b55152..2fcde4398856f17b55db7cc4eb1a2f364187b311 100644 (file)
@@ -25,11 +25,11 @@ pub enum Platform {
     PluginAndTarget,
 }
 
-pub struct Context<'a> {
-    pub config: &'a Config,
+pub struct Context<'a, 'cfg: 'a> {
+    pub config: &'cfg Config,
     pub resolve: &'a Resolve,
-    pub sources: &'a SourceMap<'a>,
-    pub compilation: Compilation,
+    pub sources: &'a SourceMap<'cfg>,
+    pub compilation: Compilation<'cfg>,
     pub build_state: Arc<BuildState>,
     pub exec_engine: Arc<Box<ExecEngine>>,
     pub fingerprints: HashMap<(&'a PackageId, &'a Target, &'a Profile, Kind),
@@ -49,23 +49,24 @@ pub struct Context<'a> {
     profiles: &'a Profiles,
 }
 
-impl<'a> Context<'a> {
+impl<'a, 'cfg> Context<'a, 'cfg> {
     pub fn new(resolve: &'a Resolve,
-               sources: &'a SourceMap<'a>,
+               sources: &'a SourceMap<'cfg>,
                deps: &'a PackageSet,
-               config: &'a Config,
+               config: &'cfg Config,
                host: Layout,
                target_layout: Option<Layout>,
                root_pkg: &Package,
                build_config: BuildConfig,
-               profiles: &'a Profiles) -> CargoResult<Context<'a>> {
+               profiles: &'a Profiles) -> CargoResult<Context<'a, 'cfg>> {
         let target = build_config.requested_target.clone();
         let target = target.as_ref().map(|s| &s[..]);
-        let (target_dylib, target_exe) = try!(Context::filename_parts(target));
+        let (target_dylib, target_exe) = try!(Context::filename_parts(target,
+                                                                      config));
         let (host_dylib, host_exe) = if build_config.requested_target.is_none() {
             (target_dylib.clone(), target_exe.clone())
         } else {
-            try!(Context::filename_parts(None))
+            try!(Context::filename_parts(None, config))
         };
         let target_triple = target.unwrap_or(config.rustc_host()).to_string();
         let engine = build_config.exec_engine.as_ref().cloned().unwrap_or({
@@ -84,7 +85,7 @@ impl<'a> Context<'a> {
             host_dylib: host_dylib,
             host_exe: host_exe,
             requirements: HashMap::new(),
-            compilation: Compilation::new(root_pkg),
+            compilation: Compilation::new(root_pkg, config),
             build_state: Arc::new(BuildState::new(&build_config, deps)),
             build_config: build_config,
             exec_engine: engine,
@@ -96,9 +97,9 @@ impl<'a> Context<'a> {
 
     /// Run `rustc` to discover the dylib prefix/suffix for the target
     /// specified as well as the exe suffix
-    fn filename_parts(target: Option<&str>)
+    fn filename_parts(target: Option<&str>, cfg: &Config)
                       -> CargoResult<(Option<(String, String)>, String)> {
-        let mut process = try!(util::process(util::rustc()));
+        let mut process = try!(util::process(cfg.rustc()));
         process.arg("-")
                .arg("--crate-name").arg("_")
                .arg("--crate-type").arg("dylib")
index 3d3a17d8ba7ba195d27cf9b343ecea8dcc65c8d8..41a3188bbf5c309685d0dbe997ec0cae88ef87f8 100644 (file)
@@ -4,7 +4,8 @@ use std::fmt;
 use std::path::Path;
 use std::process::Output;
 
-use util::{self, CargoResult, ProcessError, ProcessBuilder, process};
+use util::{CargoResult, ProcessError, ProcessBuilder, process};
+use util::Config;
 
 /// Trait for objects that can execute commands.
 pub trait ExecEngine: Send + Sync {
@@ -35,11 +36,12 @@ pub struct CommandPrototype {
 }
 
 impl CommandPrototype {
-    pub fn new(ty: CommandType) -> CargoResult<CommandPrototype> {
+    pub fn new(ty: CommandType, config: &Config)
+               -> CargoResult<CommandPrototype> {
         Ok(CommandPrototype {
             builder: try!(match ty {
-                CommandType::Rustc => process(util::rustc()),
-                CommandType::Rustdoc => process(util::rustdoc()),
+                CommandType::Rustc => process(config.rustc()),
+                CommandType::Rustdoc => process(config.rustdoc()),
                 CommandType::Target(ref s) |
                 CommandType::Host(ref s) => process(s),
             }),
index c7311849016d21abae4fb117e95abced2436b838..bbcb513ebccebf13c2ee905924099243fca6e5a6 100644 (file)
@@ -39,11 +39,11 @@ pub type Preparation = (Freshness, Work, Work);
 /// This function will calculate the fingerprint for a target and prepare the
 /// work necessary to either write the fingerprint or copy over all fresh files
 /// from the old directories to their new locations.
-pub fn prepare_target<'a>(cx: &mut Context<'a>,
-                          pkg: &'a Package,
-                          target: &'a Target,
-                          profile: &'a Profile,
-                          kind: Kind) -> CargoResult<Preparation> {
+pub fn prepare_target<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
+                                pkg: &'a Package,
+                                target: &'a Target,
+                                profile: &'a Profile,
+                                kind: Kind) -> CargoResult<Preparation> {
     let _p = profile::start(format!("fingerprint: {} / {}",
                                     pkg.package_id(), target.name()));
     let new = dir(cx, pkg, kind);
@@ -131,12 +131,12 @@ impl Fingerprint {
 ///
 /// Information like file modification time is only calculated for path
 /// dependencies and is calculated in `calculate_target_fresh`.
-fn calculate<'a>(cx: &mut Context<'a>,
-                 pkg: &'a Package,
-                 target: &'a Target,
-                 profile: &'a Profile,
-                 kind: Kind)
-                 -> CargoResult<Fingerprint> {
+fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
+                       pkg: &'a Package,
+                       target: &'a Target,
+                       profile: &'a Profile,
+                       kind: Kind)
+                       -> CargoResult<Fingerprint> {
     let key = (pkg.package_id(), target, profile, kind);
     match cx.fingerprints.get(&key) {
         Some(s) => return Ok(s.clone()),
index 24f160393e3fd454de33c8abeb23f7ee42079c2f..aebd034108cb0732e3381fc1d54d1f8192751914 100644 (file)
@@ -3,7 +3,7 @@ use std::env;
 use std::ffi::OsString;
 use std::fs;
 use std::io::prelude::*;
-use std::path::{self, PathBuf};
+use std::path::{self, Path, PathBuf};
 use std::sync::Arc;
 
 use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve};
@@ -56,8 +56,8 @@ pub struct TargetConfig {
 ///
 /// The second element of the tuple returned is the target triple that rustc
 /// is a host for.
-pub fn rustc_version() -> CargoResult<(String, String)> {
-    let output = try!(try!(util::process(util::rustc()))
+pub fn rustc_version<P: AsRef<Path>>(rustc: P) -> CargoResult<(String, String)> {
+    let output = try!(try!(util::process(rustc.as_ref()))
         .arg("-vV")
         .exec_with_output());
     let output = try!(String::from_utf8(output.stdout).map_err(|_| {
@@ -77,17 +77,17 @@ pub fn rustc_version() -> CargoResult<(String, String)> {
 
 // Returns a mapping of the root package plus its immediate dependencies to
 // where the compiled libraries are all located.
-pub fn compile_targets<'a>(targets: &[(&'a Target, &'a Profile)],
-                           pkg: &'a Package,
-                           deps: &PackageSet,
-                           resolve: &'a Resolve,
-                           sources: &'a SourceMap<'a>,
-                           config: &'a Config,
-                           build_config: BuildConfig,
-                           profiles: &'a Profiles)
-                           -> CargoResult<Compilation> {
+pub fn compile_targets<'a, 'cfg: 'a>(targets: &[(&'a Target, &'a Profile)],
+                                     pkg: &'a Package,
+                                     deps: &'a PackageSet,
+                                     resolve: &'a Resolve,
+                                     sources: &'a SourceMap<'cfg>,
+                                     config: &'cfg Config,
+                                     build_config: BuildConfig,
+                                     profiles: &'a Profiles)
+                                     -> CargoResult<Compilation<'cfg>> {
     if targets.is_empty() {
-        return Ok(Compilation::new(pkg))
+        return Ok(Compilation::new(pkg, config))
     }
 
     debug!("compile_targets: {}", pkg);
@@ -181,10 +181,10 @@ pub fn compile_targets<'a>(targets: &[(&'a Target, &'a Profile)],
     Ok(cx.compilation)
 }
 
-fn compile<'a>(targets: &[(&'a Target, &'a Profile)],
-               pkg: &'a Package,
-               cx: &mut Context<'a>,
-               jobs: &mut JobQueue<'a>) -> CargoResult<()> {
+fn compile<'a, 'cfg>(targets: &[(&'a Target, &'a Profile)],
+                     pkg: &'a Package,
+                     cx: &mut Context<'a, 'cfg>,
+                     jobs: &mut JobQueue<'a>) -> CargoResult<()> {
     debug!("compile_pkg; pkg={}", pkg);
     let profiling_marker = profile::start(format!("preparing: {}", pkg));
 
@@ -292,10 +292,10 @@ fn compile<'a>(targets: &[(&'a Target, &'a Profile)],
     Ok(())
 }
 
-fn prepare_init<'a>(cx: &mut Context<'a>,
-                    pkg: &'a Package,
-                    jobs: &mut JobQueue<'a>,
-                    visited: &mut HashSet<&'a PackageId>) {
+fn prepare_init<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,
+                          pkg: &'a Package,
+                          jobs: &mut JobQueue<'a>,
+                          visited: &mut HashSet<&'a PackageId>) {
     if !visited.insert(pkg.package_id()) { return }
 
     // Set up all dependencies
index 360d1b7d40fe0152a2364c9711f4e27cef52d871..631ffae52a2492b678d98765cec1305553a1eea3 100644 (file)
@@ -101,10 +101,10 @@ pub fn run_benches(manifest_path: &Path,
     Ok(try!(build_and_run(manifest_path, options, &args)).err())
 }
 
-fn build_and_run(manifest_path: &Path,
-                 options: &TestOptions,
-                 test_args: &[String])
-                 -> CargoResult<Result<Compilation, ProcessError>> {
+fn build_and_run<'a>(manifest_path: &Path,
+                     options: &TestOptions<'a>,
+                     test_args: &[String])
+                     -> CargoResult<Result<Compilation<'a>, ProcessError>> {
     let config = options.compile_opts.config;
     let mut source = try!(PathSource::for_path(&manifest_path.parent().unwrap(),
                                                config));
index af567da54fa395540f2fce6e282a221599923ed9..65f119bae22de00b87d0ff30423870bf93ee6486 100644 (file)
@@ -2,6 +2,7 @@ use std::cell::{RefCell, RefMut, Ref, Cell};
 use std::collections::hash_map::Entry::{Occupied, Vacant};
 use std::collections::hash_map::{HashMap};
 use std::env;
+use std::ffi::OsString;
 use std::fmt;
 use std::fs::{self, File};
 use std::io::prelude::*;
@@ -27,6 +28,8 @@ pub struct Config {
     values: RefCell<HashMap<String, ConfigValue>>,
     values_loaded: Cell<bool>,
     cwd: PathBuf,
+    rustc: PathBuf,
+    rustdoc: PathBuf,
 }
 
 impl Config {
@@ -34,20 +37,29 @@ impl Config {
         let cwd = try!(env::current_dir().chain_error(|| {
             human("couldn't get the current directory of the process")
         }));
-        let (rustc_version, rustc_host) = try!(ops::rustc_version());
 
-        Ok(Config {
+        let mut cfg = Config {
             home_path: try!(homedir().chain_error(|| {
                 human("Cargo couldn't find your home directory. \
                       This probably means that $HOME was not set.")
             })),
             shell: RefCell::new(shell),
-            rustc_version: rustc_version,
-            rustc_host: rustc_host,
+            rustc_version: String::new(),
+            rustc_host: String::new(),
             cwd: cwd,
             values: RefCell::new(HashMap::new()),
             values_loaded: Cell::new(false),
-        })
+            rustc: PathBuf::from("rustc"),
+            rustdoc: PathBuf::from("rustdoc"),
+        };
+
+        cfg.rustc = try!(cfg.get_tool("rustc"));
+        cfg.rustdoc = try!(cfg.get_tool("rustdoc"));
+        let (rustc_version, rustc_host) = try!(ops::rustc_version(cfg.rustc()));
+        cfg.rustc_version = rustc_version;
+        cfg.rustc_host = rustc_host;
+
+        Ok(cfg)
     }
 
     pub fn home(&self) -> &Path { &self.home_path }
@@ -76,6 +88,10 @@ impl Config {
         self.shell.borrow_mut()
     }
 
+    pub fn rustc(&self) -> &Path { &self.rustc }
+
+    pub fn rustdoc(&self) -> &Path { &self.rustdoc }
+
     /// Return the output of `rustc -v verbose`
     pub fn rustc_version(&self) -> &str { &self.rustc_version }
 
@@ -189,6 +205,20 @@ impl Config {
         };
         Ok(())
     }
+
+    fn get_tool(&self, tool: &str) -> CargoResult<PathBuf> {
+        let var = format!("build.{}", tool);
+        if let Some((tool, path)) = try!(self.get_string(&var)) {
+            if tool.contains("/") || (cfg!(windows) && tool.contains("\\")) {
+                return Ok(path.join(tool))
+            }
+            return Ok(PathBuf::from(tool))
+        }
+
+        let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::<String>();
+        let tool = env::var_os(&var).unwrap_or_else(|| OsString::from(tool));
+        Ok(PathBuf::from(tool))
+    }
 }
 
 #[derive(Eq, PartialEq, Clone, RustcEncodable, RustcDecodable, Copy)]
@@ -394,14 +424,6 @@ fn homedir() -> Option<PathBuf> {
     return cargo_home.or(user_home);
 }
 
-pub fn rustc() -> String {
-    env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string())
-}
-
-pub fn rustdoc() -> String {
-    env::var("RUSTDOC").unwrap_or_else(|_| "rustdoc".to_string())
-}
-
 fn walk_tree<F>(pwd: &Path, mut walk: F) -> CargoResult<()>
     where F: FnMut(File, &Path) -> CargoResult<()>
 {
index ea71ae78076f814278638b902ca6f3b6009e7930..e29fa5844541d6f0cbb047f00419ab8d476ad72b 100644 (file)
@@ -1,4 +1,4 @@
-pub use self::config::{Config, rustc, rustdoc};
+pub use self::config::Config;
 pub use self::process_builder::{process, ProcessBuilder};
 pub use self::errors::{CargoResult, CargoError, ChainError, CliResult};
 pub use self::errors::{CliError, ProcessError};
index 32b6d3d51ecc9059eb6541ecd1034f960bd0d791..3261e5cde17ce9ebd2fff7929db62111c503db52 100644 (file)
@@ -76,7 +76,9 @@ proxy = "..."     # HTTP proxy to use for HTTP requests (defaults to none)
 timeout = 60000   # Timeout for each HTTP request, in milliseconds
 
 [build]
-jobs = 1        # number of jobs to run by default (default to # cpus)
+jobs = 1             # number of jobs to run by default (default to # cpus)
+rustc = "rustc"      # path to the compiler to execute
+rustdoc = "rustdoc"  # path to the doc generator to execute
 ```
 
 # Environment Variables
index 526245c81c289c2630d2841f9ed62ac3fe84e9e9..c76d505bd1ecc4ee8850d49f0cf0dd63c6e7eade 100644 (file)
@@ -102,10 +102,7 @@ test!(bad5 {
     assert_that(foo.cargo("new")
                    .arg("-v").arg("foo").cwd(&foo.root().join("foo")),
                 execs().with_status(101).with_stderr("\
-Failed to create project `foo` at `[..]`
-
-Caused by:
-  Couldn't load Cargo configuration
+Couldn't load Cargo configuration
 
 Caused by:
   failed to merge key `foo` between files:
@@ -186,10 +183,7 @@ test!(invalid_global_config {
 
     assert_that(foo.cargo_process("build").arg("-v"),
                 execs().with_status(101).with_stderr("\
-failed to parse manifest at `[..]Cargo.toml`
-
-Caused by:
-  Couldn't load Cargo configuration
+Couldn't load Cargo configuration
 
 Caused by:
   could not parse TOML configuration in `[..]config`
index 0a50d770e9ba65519840f7b20f283014b8b6bde7..cc17a8c6523106cfebbd6232dc719425cc531b9a 100644 (file)
@@ -9,7 +9,6 @@ use support::{COMPILING, RUNNING, ProjectBuilder};
 use hamcrest::{assert_that, existing_file, is_not};
 use support::paths::CargoPathExt;
 use cargo::util::process;
-use cargo::ops::rustc_version;
 
 fn setup() {
 }
@@ -1449,7 +1448,7 @@ Caused by:
 });
 
 test!(cargo_platform_specific_dependency {
-    let (_, host) = rustc_version().unwrap();
+    let host = ::rustc_host();
     let p = project("foo")
         .file("Cargo.toml", &format!(r#"
             [project]
@@ -1776,8 +1775,7 @@ test!(rustc_env_var {
 Could not execute process `rustc-that-does-not-exist -vV` ([..])
 
 Caused by:
-[..]
-"));
+[..]".to_string() + if cfg!(windows) {"\n[..]\n"} else {"\n"}));
     assert_that(&p.bin("a"), is_not(existing_file()));
 });
 
index 65173c83bf50c3e9c12b89a4df0bccc6e1397b7b..8b1061633fcd943b0fa211bfbae2eb1671c5643a 100644 (file)
@@ -251,7 +251,7 @@ linked to by one package
 });
 
 test!(overrides_and_links {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
 
     let p = project("foo")
         .file("Cargo.toml", r#"
@@ -302,7 +302,7 @@ test!(overrides_and_links {
 });
 
 test!(unused_overrides {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
 
     let p = project("foo")
         .file("Cargo.toml", r#"
@@ -521,7 +521,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
 });
 
 test!(propagation_of_l_flags {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
     let p = project("foo")
         .file("Cargo.toml", r#"
             [project]
@@ -579,7 +579,7 @@ test!(propagation_of_l_flags {
 });
 
 test!(propagation_of_l_flags_new {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
     let p = project("foo")
         .file("Cargo.toml", r#"
             [project]
@@ -673,7 +673,7 @@ test!(build_deps_simple {
 });
 
 test!(build_deps_not_for_normal {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
     let p = project("foo")
         .file("Cargo.toml", r#"
             [project]
@@ -1276,7 +1276,7 @@ test!(cfg_feedback {
 });
 
 test!(cfg_override {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
 
     let p = project("foo")
         .file("Cargo.toml", r#"
index 3417d01e60efe5bb829bea71d7c02e7071c402b8..434ffd67653c71a0289cc1d49a197f1157ef2214 100644 (file)
@@ -223,7 +223,7 @@ test!(doctest_a_plugin {
 
 // See #1515
 test!(native_plugin_dependency_with_custom_ar_linker {
-    let (_, target) = ::cargo::ops::rustc_version().unwrap();
+    let target = ::rustc_host();
 
     let foo = project("foo")
         .file("Cargo.toml", r#"
index a650ec1b165e11941c1a72b606de239c35daabf6..57bdd59fa9c067e97d7c640af6411469072d98f0 100644 (file)
@@ -4,7 +4,6 @@ use support::{project, execs, basic_bin_manifest};
 use support::{RUNNING, COMPILING, DOCTEST};
 use hamcrest::{assert_that, existing_file};
 use cargo::util::process;
-use cargo::ops::rustc_version;
 
 fn setup() {
 }
@@ -491,7 +490,7 @@ test!(build_script_needed_for_host_and_target {
     if disabled() { return }
 
     let target = alternate();
-    let (_, host) = rustc_version().unwrap();
+    let host = ::rustc_host();
     let p = project("foo")
         .file("Cargo.toml", r#"
             [package]
index 1b72798f037bf0e6bece4e2d78d5df258ae72bfc..59b5b4c58160d47baaa19820f18729dc39107488 100644 (file)
@@ -54,3 +54,7 @@ mod test_cargo_search;
 mod test_cargo_test;
 mod test_cargo_version;
 mod test_shell;
+
+fn rustc_host() -> String {
+    cargo::ops::rustc_version("rustc").unwrap().1
+}